home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / chebyshev.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  87 lines

  1. ; $Id: chebyshev.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1986-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. FUNCTION CHEBYSHEV,D,N
  8. ;+
  9. ; NAME:
  10. ;    CHEBYSHEV
  11. ;
  12. ; PURPOSE:
  13. ;    Implements forward and reverse Chebyshev polynomial expansion of
  14. ;    a set of data.
  15. ;
  16. ; CATAGORY:
  17. ;    Mathematics.
  18. ;
  19. ; CALLING SEQUENCE:
  20. ;    Result = CHEBYSHEV(D, N)
  21. ;
  22. ; INPUT:
  23. ;    D:  A vector containing the values at the zeros of Chebyshev
  24. ;        polynomial.
  25. ;
  26. ;    N:  A flag that, if set to -1, returns a set of Chebyshev polynomials.
  27. ;        If set to +1, the original data is returned.
  28. ;
  29. ; OUTPUT:
  30. ;    Returns either the set of Chebyshev polynomials or the original
  31. ;    data depending on the value of N.
  32. ;
  33. ; COMMON BLOCKS:
  34. ;    None.
  35. ;
  36. ; SIDE EFFECTS:
  37. ;    Results from this function are subject to roundoff error given
  38. ;    discontinuous data.
  39. ;
  40. ; RESTRICTIONS:                                           
  41. ;    Unknown.
  42. ;
  43. ; PROCEDURE:
  44. ;    Straightforward implementation of recursion formula. 
  45. ;
  46. ; REVISION HISTORY:
  47. ;    Jan, 1986  Written by Leonard Kramer, U. of Maryland
  48. ;           University Research Foundation
  49. ;-    
  50.     ON_ERROR,2              ;Return to caller if an error occurs    
  51.     IF (N_PARAMS(0) NE 2 ) THEN BEGIN
  52.       PRINT,'two parameters required'
  53.           STOP
  54.     ENDIF
  55.      UNITY =(ABS(D[0])+1.)/(ABS(D[0])+1.)
  56.         NL=N_ELEMENTS(D)
  57.     NE2=(NL-1.)/2.
  58.     C=TRANSPOSE([TRANSPOSE(D),TRANSPOSE(D)])
  59.     C[*,0]=1.
  60.     X = cos(!Pi * (findgen(NL) + .5)/Nl)
  61.     C[0,1]=X
  62.     T=D
  63.         CASE N OF 
  64.     -1: BEGIN
  65.           FOR I = 0, 1 DO T[I] = 2 * TOTAL(D * C[*,I])/NL
  66.         FOR I=2,NL-1 DO BEGIN
  67.         SAVE=C[*,1]
  68.         C[0,1]= 2.*X*C[*,1]-C[*,0]
  69.         C[0,0]=SAVE
  70.             T[I] = 2 * TOTAL( D * C[*, 1])/NL
  71.       ENDFOR
  72.       END
  73.     1: BEGIN
  74.           T = fltarr(NL) - .5 * D[0]
  75.       FOR I=0,1 DO T = T + D[I] * C[*,I]
  76.       FOR I=2,NL-1 DO BEGIN
  77.         SAVE=C[*,1]
  78.         C[0,1]= 2.*X*C[*,1]-C[*,0]
  79.         C[0,0]=SAVE
  80.         T=T+D[I]*C[*,1]
  81.       ENDFOR
  82.       END
  83.     ELSE:
  84.     ENDCASE
  85.     RETURN,T
  86. END
  87.